#include "Common.h"
#include "MultiRenderTarget.h"
#include "Render.h"

MultiRenderTarget::MultiRenderTarget(int width, int height, D3DFORMAT format, bool depth, int num)
	: RenderTarget(width, height, format, depth)
	, mNum(Min(num, MAX_MRT_NUM))
{
	for (int i = 0; i < MAX_MRT_NUM; i++)
	{
		mTextures[i] = NULL;
		mSurfaces[i] = NULL;
	}
}

MultiRenderTarget::~MultiRenderTarget()
{
}

void MultiRenderTarget::Init()
{
	for (int i = 0; i < mNum; i++)
	{
		mTextures[i] = Render::Instance().CreateTexture(mWidth, mHeight, mFormat, mDepth);
		if (mTextures[i] != NULL)
			mTextures[i]->GetSurfaceLevel(0, &mSurfaces[i]);
	}
}


void MultiRenderTarget::Release()
{
	for (int i = 0; i < mNum; i++)
	{
		if (mSurfaces[i] != NULL) mSurfaces[i]->Release();
		if (mTextures[i] != NULL) mTextures[i]->Release();

		mSurfaces[i] = NULL;
		mTextures[i] = NULL;
	}
}

void MultiRenderTarget::Attach()
{
	for (int i = 0; i < mNum; i++)
	{
	}
}


void MultiRenderTarget::Dettach()
{
	for (int i = 0; i < mNum; i++)
	{
	}
}
